package org.ami.onlineschool.dataAccess;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import org.ami.onlineschool.model.Student;

public class StudentListDataAccess extends AbstractDataAccess<List<Student>> {

	private static final String STUDENT_LIST_XML_FILE = "/students.xml";

	public StudentListDataAccess(String dirPath) {
		super(dirPath, STUDENT_LIST_XML_FILE);
	}

	public List<Student> getStudents() {
		return getTargetObject();
	}

	public void saveStudentListToDisk() throws FileNotFoundException {
		saveTargetObjectToDisk();
		
	}

	@Override
	protected List<Student> initializeTargetObject() {
		return new ArrayList<Student>();
	}

	public List<Student> getStudents(List<String> ids) {
		List<Student> students = getStudents();
		List<Student> filtered = new ArrayList<Student>();
		for (Student student : students) {
			if(ids.contains(student.getId())) // FIXME: bad performance here. Use data structures that can use binary search.
				filtered.add(student);
		}
		return filtered;
	}
}
